﻿// JavaScript Document

function getElementsByClassName(n) {
	var classElements = [],allElements = document.getElementsByTagName('*');
	for (var i=0; i< allElements.length; i++ )
   {
	   if (allElements[i].className == n ) {
		   classElements[classElements.length] = allElements[i];
		}
   }
   return classElements;
}
function showDivInfo(classname){
	  var divp=getElementsByClassName(classname);	  
	  if(divp.length<1)return false;	  
	  for(var i=0,len=divp.length;i<len;i++){
		divp[i].onmouseover=function(){			
			for(var j=0,jlen=divp.length;j<jlen;j++){				
				divp[j].getElementsByTagName("ol")[0].style.display="none";
			}
			this.getElementsByTagName("ol")[0].style.display="";
		}
	  }
}

// 显示class下的 ol
//showDivInfo("nb913a")



//图片保持比例控制
//onload="imgb(this,90,90)"
function imgs(ImgD,width_s,height_s){

var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=width_s/height_s){
if(image.width>width_s){
ImgD.width=width_s;
ImgD.height=(image.height*width_s)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>height_s){
ImgD.height=height_s;
ImgD.width=(image.width*height_s)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}

}

function imgb(ImgD,width_s,height_s){

var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=width_s/height_s){

ImgD.width=width_s;
ImgD.height=(image.height*width_s)/image.width;

}
else{

ImgD.height=height_s;
ImgD.width=(image.width*height_s)/image.height;

}
}

}



// js控制div 显示 隐藏 用于幻灯
// 自动播放 setInterval("jskv('kk_',{$zongshu})",2000); 
function jskdiv(name,id,zongm){
	if(id==0){id=zongm}
	if(id>zongm){id=1}
	for(i=1;i<=zongm;i++){
		var con=document.getElementById(name+i);
		if(i==id){con.style.display = "block"}else{ con.style.display = "none"}
	}
}


function jskv(divname,zons){
	var hh=0;
	for(j=1;j<=zons;j++){
		var nnn=document.getElementById(divname+j);
		if(nnn.style.display == "block"){ hh=j;}
	}
	
	var m=hh+1;
	jskdiv(divname,m,zons);
}







//load完后 重新加载 div 内容的 替换
//jiazai(relad,'shiji','mubiao');
function jiazai(func,mt,mc) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func(mt,mc);
			} else {  
				window.onload = function() {
				oldonload();
				func(mt,mc);
				}
			}
	}
function relad(shiji,mubiao){
	
	insertEl = document.getElementById(mubiao);
	insertEg = document.getElementById(shiji);
	insertEl.innerHTML = insertEg.innerHTML ;
	
	
	}





//加入收藏
//<a onclick="javascript:jiarushoucang('http://as.qsg.com/', '标题');return false" href="#">收藏地地址</a>
function jiarushoucang(sURL, sTitle) {
	try {
		if(window.sidebar){  
			//for Firefox
			window.sidebar.addPanel(sTitle, sURL, "");
		}else if(window.external){  
			//for IE
			window.external.AddFavorite(sURL, sTitle);
		}else if(window.opera && window.print){ 
			// for opera
			return true;
		}else{
			alert("您所使用的浏览器暂不支持此功能，建议使用Ctrl+D进行添加.");
		}
	} catch (e) {
		alert("您所使用的浏览器暂不支持此功能，建议使用Ctrl+D进行添加.");
	}
}






//浮动定位
//jQuery("#n_lianxi").smartFloat();

jQuery.fn.smartFloat = function() {
    var position = function(element) {
        var top = element.position().top, pos = element.css("position");
        jQuery(window).scroll(function() {
            var scrolls = jQuery(this).scrollTop();
            if (scrolls > top) {
                if (window.XMLHttpRequest) {
                    element.css({
                        position: "fixed",
                        top: 0
                    });    
                } else {
                    element.css({
                        top: scrolls
                    });    
                }
            }else {
                element.css({
                    position: "absolute",
                    top: top
                });    
            }
        });
    };
    return jQuery(this).each(function() {
        position(jQuery(this));                         
    });
};
